package com.linkgie.galaxyframework.crypto;

import com.linkgie.galaxyframework.utils.HexUtils;

class HashAddressAlgorithms {

    static String createName(String prefix, Algorithm firstHashAlgorithm, Algorithm secondHashAlgorithm){
        return createName(prefix, firstHashAlgorithm, secondHashAlgorithm, null);
    }

    static String createName(String prefix, Algorithm firstHashAlgorithm, Algorithm secondHashAlgorithm, Long seed){
        
        if (firstHashAlgorithm.getType() != CryptographyType.HASH) {
            throw new IllegalArgumentException("Illegal first-hash-algorithm argument! It's not a hash algorithm!");
        }
        if (secondHashAlgorithm.getType() != CryptographyType.HASH) {
            throw new IllegalArgumentException("Illegal second-hash-algorithm argument! It's not a hash algorithm!");
        }

        if (seed == null) {
            String algorithm = String.format("%s-%s-%s", prefix, firstHashAlgorithm.getName(), secondHashAlgorithm.getName());
            return algorithm;
        }else{
            String hexSeed = HexUtils.encode(seed);
            String algorithm = String.format("%s-%s-%s-%s", prefix, firstHashAlgorithm.getName(), secondHashAlgorithm.getName(), hexSeed);
            return algorithm;
        }
    }

}
